<?php
/**
 * User: hoangnq
 * Date: 11/10/11
 * Time: 2:05 PM
 */
/**
 * Funcion show tree of cats
 * @return string
 */
function get_list_cats($params = array())
{
    $ci =& get_instance();
    $params = array_merge(array(
                               'tree' => array(),
                               'parent_id' => 0,
                               'level' => 0,
                               'type' => 'blog_categories'
                          ), $params);

    extract($params);

    if (empty($tree)) {
        if ($objs = $ci->db->select('id, parent, title')->get('blog_categories')->result()) {
            foreach ($objs as $obj)
            {
                $tree[$obj->parent][] = $obj;
            }
        }
    }
    if (!isset($tree[$parent_id])) {
        return;
    }
    $arr = array();
    foreach ($tree[$parent_id] as $item)
    {
        $arr[$item->id] = $item->id . '=' . $item->title;
    }

    return $arr;
}